﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows.Input;
using System.Windows;
using System.Xml.Serialization;
using System.IO;
using Microsoft.Win32;
using System.Windows.Media.Animation;
using System.Windows.Media;

namespace Guitar
{
    public partial class MainWindow
    {
        /*Ogbet de gestion des transformation global */
        private DoubleAnimation da = new DoubleAnimation();
        private TranslateTransform rt = new TranslateTransform();

        /***************************************************************************
         *                       EVENEMENTS DE MAINWINDOW
         ***************************************************************************/

        private void button_fullScreen_Click(object sender, RoutedEventArgs e)
        {
            fullScreen();
        }


        /* Permet de gérer tout les raccourcis clavier de l'application*/
        private void window_KeyDown(object sender, KeyEventArgs e)
        {

            switch (e.Key)
            {
                case Key.F11: ; fullScreen(); break; // Plein écran

                // Zoom
                case Key.OemPlus: zoomSlider.Value+=0.05; break;
                case Key.OemMinus: zoomSlider.Value -= 0.05; break;
                case Key.Add: zoomSlider.Value += 0.05; break;
                case Key.Subtract: zoomSlider.Value -= 0.05; break;
                default: break;
            }
        }



        private void panelLecteur_MouseEnter(object sender, MouseEventArgs e)
        {
            panelLecteur.Opacity = 1;
        }

        private void panelLecteur_MouseLeave(object sender, MouseEventArgs e)
        {
            panelLecteur.Opacity = 0.2;
        }

        private void button5_Click(object sender, RoutedEventArgs e)
        {


        }

        private void AutoNextClick(object sender, RoutedEventArgs e)
        {
            // on exécute une action selon le mode d'affichage de la partition
            if (buttonVuePage.IsEnabled)
            {
                vueLivre.Livre.AnimateToNextPage(true, 500); vueLivre.Livre.Focus();
            }
        }

        private void AutoPreviousClick(object sender, RoutedEventArgs e)
        {

            // on exécute une action selon le mode d'affichage de la partition
            if (buttonVuePage.IsEnabled)
            {
                vueLivre.Livre.AnimateToPreviousPage(true, 500);
                vueLivre.Livre.Focus();
            }


        }

        private void zoomSlider_ValueChanged(object sender, RoutedPropertyChangedEventArgs<double> e)
        {
            if (labelZoomValue != null)
            {
                int val = Convert.ToInt32(zoomSlider.Value * 100);
                labelZoomValue.Content = "" + val.ToString() + "%";
            }

        }


        private void buttonVueLivre_Click(object sender, RoutedEventArgs e)
        {
           
            buttonVuePage.IsEnabled = true;
            buttonVueLivre.IsEnabled = false;
            AjoutLivre();
            Conteneur.Children.Clear();         
            da.From = -1000;
            da.To = 0;
            da.Duration = new Duration(TimeSpan.FromSeconds(0.6));
            Conteneur.RenderTransform = rt;
            Conteneur.Children.Add(vueLivre);
            rt.BeginAnimation(TranslateTransform.XProperty, da);           
            
            zoomSlider.Value = zoomSlider.Value / 2;
      
        }

        private void buttonVuePage_Click(object sender, RoutedEventArgs e)
        {
            

            buttonVuePage.IsEnabled = false;
            buttonVueLivre.IsEnabled = true;
            AjoutNormal();
            Conteneur.Children.Clear();           
            da.From = 1000;
            da.To = 0;
            da.Duration = new Duration(TimeSpan.FromSeconds(0.6));
          
            Conteneur.RenderTransform = rt;
            Conteneur.Children.Add(vuePage);
            rt.BeginAnimation(TranslateTransform.XProperty, da);
            
            zoomSlider.Value = zoomSlider.Value * 2;

        }

        
    }
}
